CSS Secrets by Lea Verou

CSS Secrets by Lea Verou

Author:Lea Verou
Language: eng
Format: epub
Publisher: O’Reilly Media, Inc.
Published: 2015-10-23T16:00:00+00:00


}

main::before {

content: '';

position: absolute;

top: 0; right: 0; bottom: 0; left: 0;

background: rgba(255,0,0,.5); /* for debugging */

}

We also applied a semi-transparent red background, so we can see what we’re doing, otherwise debugging becomes difficult when we’re dealing with a transparent (and therefore, invisible) element. As you can see in Figure 4.18, our pseudo-element is currently above our content, thus obscuring it. We can fix this by adding z-index: -1; (Figure 4.20).

Be careful when using a negative z-index to move a child underneath its parent: if said parent is nested within other elements with backgrounds, the child will go below those as well.

Now it’s time to replace that semi-transparent red background, with one that actually matches our backdrop, either by copying over the <body> background, or by splitting it into its own rule. Can we blur now? Let’s try it:

Why not just use background: inherit on main::before? Because then it will inherit from main, not body, so the pseudo-element will get a semi-transparent white background as well.

body, main::before {

background: url("tiger.jpg") 0 / cover fixed;

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.